#@head() 
#@header()
<title>修改经纪人</title>
#@aside("user")
<script type="text/javascript" src="#(path)/assets/js/jquery.tmpl.min.js"></script>
<style>
	.box-body{padding:5px !important}
	.select2-container{width:150px;float:left;height:35px;margin-top:10px;border-radius:0px !important;}
	.select2-container--default .select2-selection--single{height:35px;}
</style>
<div class="content-wrapper">
	<section class="content">
	<div class="nav-tabs-custom">
	#@usermenu("xgjjr")
		<div class="tab-pane active" id="tab_2">
			<div class="box-body">
				<table id="example1" style="max-width:800px;" class="table table-bordered table-striped dataTable col-md-8" role="grid" aria-describedby="example1_info">
					<tbody>
						<tr role="row" class="odd">
							<td align="right" style="width:130px;" class="sorting_1">当前客服：</td>
							<td id="agent" class="sorting_1"></td>
						</tr>
						<tr id="selectuser" role="row" class="odd">
							<td align="right" style="width:130px;" class="sorting_1">新客服：</td>
							<td class="sorting_1">
								<select id="agentlist" class="form-control"></select>
							</td>
						</tr>
					</tbody>
				</table>
			</div>
			<div class="box-footer">
				<button id="submit" type="submit" style="margin-left:10px;" class="btn btn-info ">提交</button>
			</div>
		  </div>
		</div>
	</div>
	</section>
</div>
#@footer() 
<script>
 $(document).ready(function(){
	var id = GetRequest(id).id;
	$.getJSON("/user/fullInfo?token=#(session.token??)&id="+id, function(userinfo) {
		setFormVals(userinfo.data.info);
		$.getJSON("/staff/list?token=#(session.token??)&page=1&size=99&role=agent*agent_leader", function(userli) {
			console.log(userli.data.page.list);
			$.each(userli.data.page.list, function(i, item){ 
				$("#agentlist").append("<option value ='"+item.user_id+"'>"+item.real_name+"</option>");
			});
		});
	});
	$("#submit").click(function() {
		var userid = id;
		var agentid = $("#agentlist").val();
		layer.confirm('是否确认提交？', {btn : [ '确认', '取消' ]}, function() {
			ajax("#(path)/agent/modify?token=#(session.token??)&userId="+userid+"&agentId="+agentid,{},function(data){
				if(data.code=='success'){
					layer.msg(data.msg, {icon:1},function(){
						location.href="#(path)/admin/page/user-changecustom?id="+id;
					});
				}else if(data.code=='error'){
					layer.msg(data.msg, {icon : 2});
				}
			});
		}, function() {
			layer.msg('已取消！', {icon : 1});
		});
	});
	function GetRequest() {  
	   var url = location.search; //获取url中"?"符后的字串  
	   var theRequest = new Object();  
	   if (url.indexOf("?") != -1) {  
		  var str = url.substr(1);  
		  strs = str.split("&");  
		  for(var i = 0; i < strs.length; i ++) {  
			 theRequest[strs[i].split("=")[0]]=unescape(strs[i].split("=")[1]);  
		  }  
	   }  
	   return theRequest;  
	}  
  });
</script> 
</body>
</html>